package com.tgy.algorithm.base;

public class _删除数组中重复元素 {

    public static int removeDuplicate(int[] arr) {

        if (null == arr || arr.length == 0 || arr.length == 1) {
            return 0;
        }

        int slow = 0,fast = 1;
        int count = arr.length;
        while (fast < count) {
            if(arr[slow] != arr[fast]) {
                fast++;
                slow++;
            }else {
                for (int i = fast + 1; i < count; i++) {
                    arr[i - 1] = arr[i];
                }
                count--;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        // 1 1 2 2 3 3 4 5 5
        int[] nums = new int[]{1, 1, 2, 2, 3, 3, 4, 5, 5};
        int count = removeDuplicate(nums);
        for (int i = 0; i < count; i++) {
            System.out.println(nums[i]);
        }
    }
}
